//动画  AnimatedSwitcher的demo

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class AnimatedSwitcherCounterRoute extends StatefulWidget{

  @override
  _AnimatedSwitcherCounterRouteState  createState() => _AnimatedSwitcherCounterRouteState();

}

class _AnimatedSwitcherCounterRouteState extends State{

  int _count = 0;

  @override
  Widget build(BuildContext context) {

    return MaterialApp(
      title: "测试AnimatedSwitcher的demo",
      home: Scaffold(
        body: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          AnimatedSwitcher(
            duration: const Duration(milliseconds: 500),
            transitionBuilder: (Widget child, Animation<double> animation) {
              //执行缩放动画
              return ScaleTransition(child: child, scale: animation);
            },
            child: Text(
               "$_count",
               //显示指定key，不同的key会被认为是不同的Text，这样才能执行动画
               key: ValueKey<int>(_count),
               style: Theme.of(context).textTheme.headline4,
            ),
          ),
          ElevatedButton(
            child: const Text('+1',),
            onPressed: () {
              setState(() {
                _count += 1;
              });
            },
          ),
        ],
        ),
      ),
    );
  }
}
